package com.liruo.treasureattic.config.common.util;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author:liruo
 * @Date:2022-10-23-21:26:05
 * @Desc
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //getRequestURL[http://localhost:8001/user/ignore/1/book]
        // getRequestURI[/user/ignore/1/book]
        // getServletPath[/user/ignore/1/book]
        // getPathInfo[null]
        //不需要登录的，不用检查token
        SessionHolder.set(request.getSession());
        return true;
    }
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        SessionHolder.clear();
    }

}
